<?php
require_once("config.php");

if (is_ajax())
{
	//Checks if action value exists
    if (isset($_POST["action"]) && !empty($_POST["action"]))
	{	
        $action = $_POST["action"];
		//Switch case for value of action
        switch($action)
        {
            case "test": 
            user_login($mysql);
            break;		
        }
    }
} 
/*
 * Is this an AJAX request?
 */
function is_ajax()
{
    return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
}
/*
 * Challenge Login
 */
function user_login($mysql)
{
    $return = $_POST;
	$query = array("username" => $return["username"]);
	$user = $mysql->Select("users", $query);

	if ($return["password"] == $user['password'] && $user['username'] != null){
		$return["authentication"] = true;
	} else {
		$return["authentication"] = false;
	}
    $return["json"] = json_encode($return);
    echo json_encode($return);
}
?>